/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa165.library.backend;

import cz.muni.fi.pa165.library.api.UserService;
import cz.muni.fi.pa165.library.api.UserTO;
import java.util.List;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Filip Ligac
 */
@Service
public class UserServiceImpl implements UserService {

    private UserDAO userDAO;
    private static UserServiceImpl instance = new UserServiceImpl();

    public void setUserDAO(UserDAO userDAO) {
        this.userDAO = userDAO;
    }
    
    public static UserServiceImpl getInstance() {
        return instance;
    }

    @Secured("ROLE_LIBRARIAN")
    public UserTO createUser(UserTO userTO) {
        return DTOConvertor.convertUserEntityToTO(userDAO.createUser(DTOConvertor.convertUserTOToEntity(userTO)));
    }
   
    @Secured("ROLE_LIBRARIAN")
    public UserTO findUserByEmail(String email) {
        return DTOConvertor.convertUserEntityToTO(userDAO.findUserByEmail(email));
    }
   
    @Secured("ROLE_LIBRARIAN")
    public void deleteUser(UserTO userTO) {
        userDAO.deleteUser(DTOConvertor.convertUserTOToEntity(userTO));
    }

    public void updateUser(UserTO user) {
        userDAO.updateUser(DTOConvertor.convertUserTOToEntity(user));
    }

    public UserTO findUserById(Long id) {
       return DTOConvertor.convertUserEntityToTO(userDAO.findUserById(id));
    }
}
